Setup

Loading PG&E data from CSVs

## Loading 2021 electricity files
pge_21_q1_elec <- read_csv("PG&E/PGE_2021_Q1_ElectricUsageByZip.csv")
## Rows: 7580 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_21_q2_elec <- read_csv("PG&E/PGE_2021_Q2_ElectricUsageByZip.csv")
## Rows: 7611 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2020 electricity files
pge_20_q1_elec <- read_csv("PG&E/PGE_2020_Q1_ElectricUsageByZip.csv")
## Rows: 7865 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q2_elec <- read_csv("PG&E/PGE_2020_Q2_ElectricUsageByZip.csv")
## Rows: 7791 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q3_elec <- read_csv("PG&E/PGE_2020_Q3_ElectricUsageByZip.csv")
## Rows: 7784 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q4_elec <- read_csv("PG&E/PGE_2020_Q4_ElectricUsageByZip.csv")
## Rows: 7771 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2019 electricity files
pge_19_q1_elec <- read_csv("PG&E/PGE_2019_Q1_ElectricUsageByZip.csv")
## Rows: 7870 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q2_elec <- read_csv("PG&E/PGE_2019_Q2_ElectricUsageByZip.csv")
## Rows: 7887 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q3_elec <- read_csv("PG&E/PGE_2019_Q3_ElectricUsageByZip.csv")
## Rows: 7891 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q4_elec <- read_csv("PG&E/PGE_2019_Q4_ElectricUsageByZip.csv")
## Rows: 7874 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2018 electricity files
pge_18_q1_elec <- read_csv("PG&E/PGE_2018_Q1_ElectricUsageByZip.csv")
## Rows: 7852 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q2_elec <- read_csv("PG&E/PGE_2018_Q2_ElectricUsageByZip.csv")
## Rows: 7880 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q3_elec <- read_csv("PG&E/PGE_2018_Q3_ElectricUsageByZip.csv")
## Rows: 7877 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q4_elec <- read_csv("PG&E/PGE_2018_Q4_ElectricUsageByZip.csv")
## Rows: 7875 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2017 electricity files
pge_17_q1_elec <- read_csv("PG&E/PGE_2017_Q1_ElectricUsageByZip.csv")
## Rows: 7776 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q2_elec <- read_csv("PG&E/PGE_2017_Q2_ElectricUsageByZip.csv")
## Rows: 7819 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q3_elec <- read_csv("PG&E/PGE_2017_Q3_ElectricUsageByZip.csv")
## Rows: 7842 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q4_elec <- read_csv("PG&E/PGE_2017_Q4_ElectricUsageByZip.csv")
## Rows: 10455 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#####################################################################
#Loading 2021 gas files
pge_21_q1_gas <- read_csv("PG&E/PGE_2021_Q1_GasUsageByZip.csv")
## Rows: 3458 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_21_q2_gas <- read_csv("PG&E/PGE_2021_Q2_GasUsageByZip.csv")
## Rows: 3459 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2020 electricity files
pge_20_q1_gas <- read_csv("PG&E/PGE_2020_Q1_GasUsageByZip.csv")
## Rows: 3493 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q2_gas <- read_csv("PG&E/PGE_2020_Q2_GasUsageByZip.csv")
## Rows: 3461 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q3_gas <- read_csv("PG&E/PGE_2020_Q3_GasUsageByZip.csv")
## Rows: 3459 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_20_q4_gas <- read_csv("PG&E/PGE_2020_Q4_GasUsageByZip.csv")
## Rows: 3456 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2019 electricity files
pge_19_q1_gas <- read_csv("PG&E/PGE_2019_Q1_GasUsageByZip.csv")
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q2_gas <- read_csv("PG&E/PGE_2019_Q2_GasUsageByZip.csv")
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q3_gas <- read_csv("PG&E/PGE_2019_Q3_GasUsageByZip.csv")
## Rows: 3489 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_19_q4_gas <- read_csv("PG&E/PGE_2019_Q4_GasUsageByZip.csv")
## Rows: 3490 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2018 electricity files
pge_18_q1_gas <- read_csv("PG&E/PGE_2018_Q1_GasUsageByZip.csv")
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q2_gas <- read_csv("PG&E/PGE_2018_Q2_GasUsageByZip.csv")
## Rows: 3502 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q3_gas <- read_csv("PG&E/PGE_2018_Q3_GasUsageByZip.csv")
## Rows: 3503 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_18_q4_gas <- read_csv("PG&E/PGE_2018_Q4_GasUsageByZip.csv")
## Rows: 3496 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Loading 2017 electricity files
pge_17_q1_gas <- read_csv("PG&E/PGE_2017_Q1_GasUsageByZip.csv")
## Rows: 3486 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q2_gas <- read_csv("PG&E/PGE_2017_Q2_GasUsageByZip.csv")
## Rows: 3489 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q3_gas <- read_csv("PG&E/PGE_2017_Q3_GasUsageByZip.csv")
## Rows: 3491 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pge_17_q4_gas <- read_csv("PG&E/PGE_2017_Q4_GasUsageByZip.csv")
## Rows: 4662 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Saving data into RDS files by year

# 2021 Electric
year <- 2021
quarters <- 1:2
type <- "Electric"

pge_21_elec <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_21_elec <- rbind(pge_21_elec,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_21_elec, "pge_21_elec.rds")
}
## [1] "PG&E/PGE_2021_Q1_ElectricUsageByZip.csv"
## Rows: 7580 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2021_Q2_ElectricUsageByZip.csv"
## Rows: 7611 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2020 Electric
year <- 2020
quarters <- 1:4
type <- "Electric"

pge_20_elec <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_20_elec <- rbind(pge_20_elec,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_20_elec, "pge_20_elec.rds")
}
## [1] "PG&E/PGE_2020_Q1_ElectricUsageByZip.csv"
## Rows: 7865 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q2_ElectricUsageByZip.csv"
## Rows: 7791 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q3_ElectricUsageByZip.csv"
## Rows: 7784 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q4_ElectricUsageByZip.csv"
## Rows: 7771 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2019 Electric
year <- 2019
quarters <- 1:4
type <- "Electric"

pge_19_elec <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_19_elec <- rbind(pge_19_elec,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_19_elec, "pge_19_elec.rds")
}
## [1] "PG&E/PGE_2019_Q1_ElectricUsageByZip.csv"
## Rows: 7870 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q2_ElectricUsageByZip.csv"
## Rows: 7887 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q3_ElectricUsageByZip.csv"
## Rows: 7891 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q4_ElectricUsageByZip.csv"
## Rows: 7874 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2018 Electric
year <- 2018
quarters <- 1:4
type <- "Electric"

pge_18_elec <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_18_elec <- rbind(pge_18_elec,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_18_elec, "pge_18_elec.rds")
}
## [1] "PG&E/PGE_2018_Q1_ElectricUsageByZip.csv"
## Rows: 7852 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2018_Q2_ElectricUsageByZip.csv"
## Rows: 7880 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2018_Q3_ElectricUsageByZip.csv"
## Rows: 7877 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2018_Q4_ElectricUsageByZip.csv"
## Rows: 7875 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2017 Electric
year <- 2017
quarters <- 1:4
type <- "Electric"

pge_17_elec <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_17_elec <- rbind(pge_17_elec,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_17_elec, "pge_17_elec.rds")
}
## [1] "PG&E/PGE_2017_Q1_ElectricUsageByZip.csv"
## Rows: 7776 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q2_ElectricUsageByZip.csv"
## Rows: 7819 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q3_ElectricUsageByZip.csv"
## Rows: 7842 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q4_ElectricUsageByZip.csv"
## Rows: 10455 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2021 Gas
year <- 2021
quarters <- 1:2
type <- "Gas"

pge_21_gas <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_21_gas <- rbind(pge_21_gas,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_21_gas, "pge_21_gas.rds")
}
## [1] "PG&E/PGE_2021_Q1_GasUsageByZip.csv"
## Rows: 3458 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2021_Q2_GasUsageByZip.csv"
## Rows: 3459 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2020 Gas
year <- 2020
quarters <- 1:4
type <- "Gas"

pge_20_gas <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_20_gas <- rbind(pge_20_gas,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_20_gas, "pge_20_gas.rds")
}
## [1] "PG&E/PGE_2020_Q1_GasUsageByZip.csv"
## Rows: 3493 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q2_GasUsageByZip.csv"
## Rows: 3461 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q3_GasUsageByZip.csv"
## Rows: 3459 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2020_Q4_GasUsageByZip.csv"
## Rows: 3456 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Warning: One or more parsing issues, see `problems()` for details
# 2019 Gas
year <- 2019
quarters <- 1:4
type <- "Gas"

pge_19_gas <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_19_gas <- rbind(pge_19_gas,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_19_gas, "pge_19_gas.rds")
}
## [1] "PG&E/PGE_2019_Q1_GasUsageByZip.csv"
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q2_GasUsageByZip.csv"
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q3_GasUsageByZip.csv"
## Rows: 3489 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2019_Q4_GasUsageByZip.csv"
## Rows: 3490 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#2018 Gas
year <- 2018
quarters <- 1:4
type <- "Gas"

pge_18_gas <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_18_gas <- rbind(pge_18_gas,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_18_gas, "pge_18_gas.rds")
}
## [1] "PG&E/PGE_2018_Q1_GasUsageByZip.csv"
## Rows: 3499 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2018_Q2_GasUsageByZip.csv"
## Rows: 3502 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Warning: One or more parsing issues, see `problems()` for details
## [1] "PG&E/PGE_2018_Q3_GasUsageByZip.csv"
## Rows: 3503 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2018_Q4_GasUsageByZip.csv"
## Rows: 3496 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# 2017 Gas
year <- 2017
quarters <- 1:4
type <- "Gas"

pge_17_gas <- NULL

for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PG&E/PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )

  print(filename)
  
  temp <- read_csv(filename)
  
  pge_17_gas <- rbind(pge_17_gas,temp)
  # Note rbind requires field names to be consistent for every new thing that you add.

  saveRDS(pge_17_gas, "pge_17_gas.rds")
}
## [1] "PG&E/PGE_2017_Q1_GasUsageByZip.csv"
## Rows: 3486 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q2_GasUsageByZip.csv"
## Rows: 3489 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q3_GasUsageByZip.csv"
## Rows: 3491 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (4): ZIPCODE, MONTH, YEAR, AVERAGETHM
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## [1] "PG&E/PGE_2017_Q4_GasUsageByZip.csv"
## Rows: 4662 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): CUSTOMERCLASS, COMBINED
## dbl (3): ZIPCODE, MONTH, YEAR
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Creating dataframes with all years’ data combined (for easier graphing manip)

pge_elec_all <- rbind(pge_17_elec, 
                      pge_18_elec, 
                      pge_19_elec, 
                      pge_20_elec, 
                      pge_21_elec)

pge_elec_all
## # A tibble: 143,300 × 8
##    ZIPCODE MONTH  YEAR CUSTOMERCLASS COMBINED TOTALCUSTOMERS TOTALKWH AVERAGEKWH
##      <dbl> <dbl> <dbl> <chr>         <chr>             <dbl>    <dbl>      <dbl>
##  1   93117     1  2017 Elec- Agricu… Y                     0        0         NA
##  2   93117     2  2017 Elec- Agricu… Y                     0        0         NA
##  3   93117     3  2017 Elec- Agricu… Y                     0        0         NA
##  4   93203     1  2017 Elec- Agricu… Y                     0        0         NA
##  5   93203     2  2017 Elec- Agricu… Y                     0        0         NA
##  6   93203     3  2017 Elec- Agricu… Y                   158  5041211      31906
##  7   93204     1  2017 Elec- Agricu… Y                     0        0         NA
##  8   93204     2  2017 Elec- Agricu… Y                     0        0         NA
##  9   93204     3  2017 Elec- Agricu… Y                     0        0         NA
## 10   93206     1  2017 Elec- Agricu… Y                   302  8809508      29171
## # … with 143,290 more rows
pge_gas_all <- rbind(pge_17_gas,
                     pge_18_gas,
                     pge_19_gas,
                     pge_20_gas,
                     pge_21_gas)

pge_gas_all
## # A tibble: 63,891 × 8
##    ZIPCODE MONTH  YEAR CUSTOMERCLASS   COMBINED TOTALCUSTOMERS TOTALTHM AVERAGETHM
##      <dbl> <dbl> <dbl> <chr>           <chr>             <dbl>    <dbl>      <dbl>
##  1   92304     1  2017 Gas- Commercial Y                     0        0         NA
##  2   92304     2  2017 Gas- Commercial Y                     0        0         NA
##  3   92304     3  2017 Gas- Commercial Y                     0        0         NA
##  4   92365     1  2017 Gas- Commercial Y                     0        0         NA
##  5   92365     2  2017 Gas- Commercial Y                     0        0         NA
##  6   92365     3  2017 Gas- Commercial Y                     0        0         NA
##  7   93203     1  2017 Gas- Commercial Y                     0        0         NA
##  8   93203     2  2017 Gas- Commercial Y                     0        0         NA
##  9   93203     3  2017 Gas- Commercial Y                     0        0         NA
## 10   93204     1  2017 Gas- Commercial Y                     0        0         NA
## # … with 63,881 more rows

Simplifying two aggregated dataframes via piped example template in Ch 1.7

pge_elec_final <-
  pge_elec_all %>% 
  filter(
    CUSTOMERCLASS %in% 
      c(
        "Elec- Residential",
        "Elec- Commercial"
      )
  ) %>% 
  select(
    -c(COMBINED, AVERAGEKWH)
  ) %>% 
  group_by(YEAR, MONTH, CUSTOMERCLASS) %>% 
  summarize(
    TOTALKWH = 
      sum(
        TOTALKWH, 
        na.rm = T
      ),
    TOTALCUSTOMERS =
      sum(
        TOTALCUSTOMERS,
        na.rm = T
      )
  ) %>% 
  mutate(
    AVERAGEKWH =
      TOTALKWH/TOTALCUSTOMERS
  )
## `summarise()` has grouped output by 'YEAR', 'MONTH'. You can override using the `.groups` argument.
pge_elec_final
## # A tibble: 108 × 6
## # Groups:   YEAR, MONTH [54]
##     YEAR MONTH CUSTOMERCLASS       TOTALKWH TOTALCUSTOMERS AVERAGEKWH
##    <dbl> <dbl> <chr>                  <dbl>          <dbl>      <dbl>
##  1  2017     1 Elec- Commercial  2518133184         312242      8065.
##  2  2017     1 Elec- Residential 2696632298        4427009       609.
##  3  2017     2 Elec- Commercial  2186409895         312327      7000.
##  4  2017     2 Elec- Residential 2089405296        4429320       472.
##  5  2017     3 Elec- Commercial  2328765919         312586      7450.
##  6  2017     3 Elec- Residential 2007875145        4432096       453.
##  7  2017     4 Elec- Commercial  2260528589         313499      7211.
##  8  2017     4 Elec- Residential 1838107707        4437095       414.
##  9  2017     5 Elec- Commercial  2472760712         313795      7880.
## 10  2017     5 Elec- Residential 2070656073        4438946       466.
## # … with 98 more rows
pge_gas_final <-
  pge_gas_all %>% 
  filter(
    CUSTOMERCLASS %in% 
      c(
        "Gas- Residential",
        "Gas- Commercial"
      )
  ) %>% 
  select(
    -c(COMBINED, AVERAGETHM)
  ) %>% 
  group_by(YEAR, MONTH, CUSTOMERCLASS) %>% 
  summarize(
    TOTALTHM = 
      sum(
        TOTALTHM, 
        na.rm = T
      ),
    TOTALCUSTOMERS =
      sum(
        TOTALCUSTOMERS,
        na.rm = T
      )
  ) %>% 
  mutate(
    AVERAGETHM =
      TOTALTHM/TOTALCUSTOMERS
  )
## `summarise()` has grouped output by 'YEAR', 'MONTH'. You can override using the `.groups` argument.
pge_gas_final
## # A tibble: 108 × 6
## # Groups:   YEAR, MONTH [54]
##     YEAR MONTH CUSTOMERCLASS     TOTALTHM TOTALCUSTOMERS AVERAGETHM
##    <dbl> <dbl> <chr>                <dbl>          <dbl>      <dbl>
##  1  2017     1 Gas- Commercial   81974539         173036      474. 
##  2  2017     1 Gas- Residential 332986863        4059858       82.0
##  3  2017     2 Gas- Commercial   57175524         173096      330. 
##  4  2017     2 Gas- Residential 214756795        4062740       52.9
##  5  2017     3 Gas- Commercial   51732816         173061      299. 
##  6  2017     3 Gas- Residential 167698331        4065227       41.3
##  7  2017     4 Gas- Commercial   42328501         172695      245. 
##  8  2017     4 Gas- Residential 128910844        4069161       31.7
##  9  2017     5 Gas- Commercial   36825348         172309      214. 
## 10  2017     5 Gas- Residential  93587412        4069311       23.0
## # … with 98 more rows

Concatenating month & year columns (for easier graphing manip)

pge_elec_final$DATE <- as.Date(
                          paste(
                            pge_elec_final$YEAR, 
                            pge_elec_final$MONTH, 
                            "01",
                            sep = "-")
                        )

pge_gas_final$DATE <- as.Date(
                          paste(
                            pge_gas_final$YEAR, 
                            pge_gas_final$MONTH, 
                            "01",
                            sep = "-")
                        )

Converting gas & electric to universal units

pge_elec_final$TOTALKBTU <- pge_elec_final$TOTALKWH * 3.412
# 3.412 is the multiplier for a conversion from KWH to kBTU
# Source: https://sciencing.com/calculate-kilowatt-hours-4902973.html

pge_gas_final$TOTALKBTU <- pge_gas_final$TOTALTHM * 100
# 100 is the approx. multiplier for a convesion from therms to kBTU
# Source: https://sciencing.com/convert-ccf-mmbtu-2825.html

Filtering remaining dataframes by customer type

pge_elec_residential <- filter(
                          pge_elec_final, 
                          CUSTOMERCLASS == "Elec- Residential")
pge_elec_commercial <- filter(
                          pge_elec_final, 
                          CUSTOMERCLASS == "Elec- Commercial")

pge_gas_residential <- filter(
                          pge_gas_final, 
                          CUSTOMERCLASS == "Gas- Residential")
pge_gas_commercial <- filter(
                          pge_gas_final, 
                          CUSTOMERCLASS == "Gas- Commercial")

Creating plots for Residential Gas & Electric (2017 - present)

pge_res_chart <- 
    ggplot() +
    geom_line(
      aes(
       x = pge_elec_residential$DATE,
       y = pge_elec_residential$TOTALKBTU,
       fill = pge_elec_residential$CUSTOMERCLASS
     ),
     stat = "identity",
     position = "stack",
     color = "purple"
   ) +
    geom_line(
      aes(
       x = pge_gas_residential$DATE,
       y = pge_gas_residential$TOTALKBTU,
       fill = pge_gas_residential$CUSTOMERCLASS
     ),
     stat = "identity",
     position = "stack",
     color = "orange"
    ) +
    labs(
      x = "Month",
      y = "KBTU",
       title = "PG&E Territory Monthly Residential Gas & Electricity Usage 
      2017-Present (in kBTUs)",
      fill = "Customer Type"
  )
## Warning: Ignoring unknown aesthetics: fill

## Warning: Ignoring unknown aesthetics: fill
pge_res_chart %>% ggplotly()

Creating plots for Commercial Gas & Electric (2017 - present)

pge_comm_chart <- 
    ggplot() +
    geom_line(
      aes(
       x = pge_elec_commercial$DATE,
       y = pge_elec_commercial$TOTALKBTU,
       fill = pge_elec_commercial$CUSTOMERCLASS
     ),
     stat = "identity",
     position = "stack",
     color = "purple"
   ) +
    geom_line(
      aes(
       x = pge_gas_commercial$DATE,
       y = pge_gas_commercial$TOTALKBTU,
       fill = pge_gas_commercial$CUSTOMERCLASS
     ),
     stat = "identity",
     position = "stack",
     color = "orange"
    ) +
    labs(
      x = "Month",
      y = "KBTU",
       title = "PG&E Territory Monthly Commercial Gas & Electricity Usage 
      2017-Present (in kBTUs)",
      fill = "Customer Type"
  )
## Warning: Ignoring unknown aesthetics: fill

## Warning: Ignoring unknown aesthetics: fill
pge_comm_chart %>% ggplotly()

Observations:

On residential customers:

Electricity usage by residential customers appears to have increased since the onset of COVID. This can be explained by differences in patterns of behavior once moving indoors. However, this may not capture the entire picture of electricity usage. The rise of Community Choice Aggregators (CCAs) within PG&E’s service territory has increased dramatically since 2018, taking away portions of PG&E’s electricity load that would otherwise be represented.

Gas usage seems to be within general trends (perhappps, slightly higher than usual), and with a marked anomaly around March 2020.

On commercial customers:

There is a significant decrease in electricity usage by commercial customers in 2020, presumably because of COVID. This is evident by the precipitous drop in usage from March 2020 onwards. This trend continues until Q2 of 2021, where usage begins to climb again.

There is a slight decline in commercial gas usage in 2020, but not as dramatic as the change with electricity usage. Perhaps this discrepancy can once again be accounted for by the shifting of electric load to CCAs and away from PG&E (CCAs do not sell gas).